import numpy as np


def tanh(x):  # 激活函数
    return (np.exp(x)-np.exp(-x))/(np.exp(x)+np.exp(-x))


class Perceptron:
    def __init__(self, num):
        self.weights = np.random.rand(num)
        self.bias = np.random.rand()  # 偏置量

    def predict(self, arr):
        total = np.dot(arr, self.weights) + self.bias
        return tanh(total)  # f(x) = tanh(wx+b)


number = 4
perceptron = Perceptron(number)
inputs = np.array([-0.8, 0.5, -0.7, 0.2])
prediction = perceptron.predict(inputs)
print("输出预测值:", prediction)
